/*********************************************************
          File Name:9.27.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 14 Sep 2015 09:30:23 PM CST
**********************************************************/

#include <iostream>
using namespace std;

#include <forward_list>

int main()
{
        forward_list<int> fls{1, 2, 3, 4, 5, 6, 7};
        auto prev = fls.before_begin();
        auto curr = fls.begin();

        // store `fls.end()` is a bad idea
        while(curr != fls.end())     // fls.remove_if()
        {
                if(*curr & 0x1)
                        curr = fls.erase_after(prev);
                else
                {
                        prev = curr;
                        curr++;
                }
        }

        for(auto x: fls)
                cout << x << " ";
        cout << endl;

        return 0;
}
